package ro.ubbcluj.cs.damate.managers.diagrams;

import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;
import org.primefaces.model.chart.LineChartSeries;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Component
@Scope("view")
public class ChartBean implements Serializable {

    private CartesianChartModel categoryModel;

    private CartesianChartModel linearModel;

    public ChartBean() {
        createCategoryModel();
        createLinearModel();
    }

    public CartesianChartModel getCategoryModel() {
        return categoryModel;
    }

    public CartesianChartModel getLinearModel() {
        return linearModel;
    }

    private void createCategoryModel() {
        categoryModel = new CartesianChartModel();

        ChartSeries boys = new ChartSeries();
        boys.setLabel("Line of codes");

        boys.set("2013-06-14", 20);
        boys.set("2013-06-15", 76);
        boys.set("2013-06-16", 90);
        boys.set("2013-06-17", 70);
        boys.set("2013-06-18", 84);

        ChartSeries girls = new ChartSeries();
        girls.setLabel("Copy/Paste");

        girls.set("2013-06-14", 10);
        girls.set("2013-06-15", 0);
        girls.set("2013-06-16", 14);
        girls.set("2013-06-17", 3);
        girls.set("2013-06-18", 6);

        categoryModel.addSeries(boys);
        categoryModel.addSeries(girls);
    }

    private void createLinearModel() {
        linearModel = new CartesianChartModel();

        LineChartSeries series1 = new LineChartSeries();
        series1.setLabel("Series 1");

        series1.set(1, 2);
        series1.set(2, 1);
        series1.set(3, 3);
        series1.set(4, 6);
        series1.set(5, 8);

        LineChartSeries series2 = new LineChartSeries();
        series2.setLabel("Series 2");
        series2.setMarkerStyle("diamond");

        series2.set(1, 6);
        series2.set(2, 3);
        series2.set(3, 2);
        series2.set(4, 7);
        series2.set(5, 9);

        linearModel.addSeries(series1);
        linearModel.addSeries(series2);
    }
}